Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mdast-util-math

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-util-math

mdast extension to parse and serialize math

  • 2.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
449K
increased by3.09%
Maintainers
2
Weekly downloads
 
Created

What is mdast-util-math?

The `mdast-util-math` package is a utility for working with math content in Markdown Abstract Syntax Trees (MDAST). It provides tools to parse and serialize math content, making it easier to handle mathematical expressions within Markdown documents.

What are mdast-util-math's main functionalities?

Parse Math Content

This feature allows you to parse Markdown content that includes inline and block math expressions. The code sample demonstrates how to use `mdast-util-math` with `remark-parse` and `remark-math` to parse a Markdown string containing a math expression.

const { fromMarkdown } = require('mdast-util-math');
const { unified } = require('unified');
const markdown = require('remark-parse');
const math = require('remark-math');

const processor = unified()
  .use(markdown)
  .use(math);

const tree = processor.parse('Here is some math: $E=mc^2$');
console.log(tree);

Serialize Math Content

This feature allows you to serialize MDAST containing math expressions back into Markdown. The code sample shows how to convert an MDAST tree with an inline math node back into a Markdown string.

const { toMarkdown } = require('mdast-util-math');
const { unified } = require('unified');
const markdown = require('remark-stringify');
const math = require('remark-math');

const tree = {
  type: 'root',
  children: [
    { type: 'paragraph', children: [
      { type: 'text', value: 'Here is some math: ' },
      { type: 'inlineMath', value: 'E=mc^2' }
    ]}
  ]
};

const processor = unified()
  .use(markdown)
  .use(math);

const result = processor.stringify(tree);
console.log(result);

Other packages similar to mdast-util-math

Keywords

FAQs

Package last updated on 28 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc